<template>
  <el-tree :data="treeData" :props="defaultProps" :default-expanded-keys="['base_city', 'base_city_1', 'base_city_1_1']" node-key="kpiCode" accordion highlight-current @node-click="handleNodeClick"/>
</template>

<script>
import { listTarget } from '@/api/drg-target-maintain/gather-target-maintain'
import XEUtils from 'xe-utils'
export default {
  name: 'SvgIcon',
  props: {
  },
  data() {
    return {
      treeData: [],
      defaultProps: {
        children: 'children',
        label: 'kpiName'
      }
    }
  },
  computed: {
  },
  mounted() {
    this.getTreeData()
  },
  methods: {
    // 获取树数据
    getTreeData() {
      let params = {}
      listTarget(params).then(res => {
        if (res.data.code === 0) {
          let listData = res.data.data
          listData.forEach((item, index) => {
            item.label = item.kpiName
            if (item.kpiCode === item.kpiFcode) {
              delete item.kpiFcode
            }
          })
          this.treeData = XEUtils.toArrayTree(listData, { strict: true, parentKey: 'kpiFcode', key: 'kpiCode', children: 'children' })[0].children
        }
      }).catch(err => err)
    },
    handleNodeClick(data) {
      // console.log(data)
      if (data.children) {
        return
      }
      // let flag = false
      // // let reg = /^mnit_city|^mnit_hosp/ // 指标编码是以mnit_city，mnit_hosp这两个开头，那么对应的页面需要有医疗机构的查询条件
      // // let result = data.kpiCode.search(reg)
      // // if (result === 0) {
      // //   flag = true
      // // }
      // if (data.modelUrl === 'hosp') {
      //   flag = true
      // }
      this.$emit('getTreeDate', data)
    }
  }
}
</script>

<style lang="scss" scoped>
.el-tree {
  height: calc(100vh - 176px);
  overflow: auto;

  /deep/ .el-tree-node__content > .el-tree-node__label {
    width: 100%;
    @include one-line-text;
  }
}
</style>
